package ccpc_2023;

import java.util.Scanner;

public class D {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        while(T-- > 0) {
            int n = sc.nextInt();
            int m = sc.nextInt();
            if(n * m % 4 != 0 || (n <= 2 && m <= 2)) {
                System.out.println("NO");
                continue;
            }
            if(n % 4 == 0 || m % 4 == 0) {
                System.out.println("YES");
                int a = n;
                int b = m;
                if(m % 4 != 0) {
                    int tmp = m;
                    m = n;
                    n = tmp;
                }
                int[][] grid = new int[n][m];
                //make sure m mod 4 == 0
                int cnt = 1;
                for(int i = 0; i < n; i++) {
                    for(int j = 0; j < m/4; j++) {
                        for(int k = 0; k < 4; k++) {
                            grid[i][k + j*4] = cnt;
                        }
                        cnt++;
                    }
                }

                if(a % 4 == 0) {
                    for(int i = 0; i < m; i++) {
                        for(int j = 0; j < n-1; j++) {
                            System.out.print(grid[j][i] + " ");
                        }
                        System.out.println(grid[n-1][i]);
                    }
                } else {
                    for(int i = 0; i < n; i++) {
                        for(int j = 0; j < m-1; j++) {
                            System.out.print(grid[i][j] + " ");
                        }
                        System.out.println(grid[i][m-1]);
                    }
                }

            } else if(n % 2==0 && m %2==0) {
                System.out.println("YES");
                int a = n;
                int b = m;
                //n * m % 4 == 0 but n % 4 != 0 and m % 4 != 0
                if ( m == 2 ) {
                    int tmp = m;
                    m = n;
                    n = tmp;
                }
                int[][] grid = new int[n][m];
                int cnt = 1;
                //suppose that m is bigger than 2
                // got n/2
                // m divide into 6 and (m - 6) / 4
                /*
                 *   which is 1 2 2 2 2 3
                 *            1 1 1 3 3 3
                 *   and 1 1 1 1
                 *       2 2 2 2
                 *
                 *
                 * */

                for(int i = 0; i < n / 2; i++) {
                    for(int l = 0;l < 2;l++) {
                        for(int j = 0; j < (m-6) / 4; j++) {
                            for(int k = 0; k < 4; k++) {
                                grid[l + i * 2][k + j * 4] = cnt;
                            }
                            cnt++;
                        }
                    }

                }

                for(int i = 0;i < n / 2; i++) {
                    grid[0 + i * 2][m - 6] = cnt;
                    grid[0 + i * 2][m - 1] = cnt + 2;
                    for(int j = m- 5; j<m - 1;j++){
                        grid[0 + i * 2][j] = cnt+1;
                    }
                    for(int j = 6;j >=4;j--)
                        grid[1 + i * 2][m - j] = cnt;
                    for(int j = 3; j >= 1;j--){
                        grid[1 + i * 2][m - j] = cnt+2;
                    }
                    cnt+=3;
                }

                if(b == 2) {
                    for(int i = 0; i < m; i++) {
                        for(int j = 0; j < n-1; j++) {
                            System.out.print(grid[j][i] + " ");
                        }
                        System.out.println(grid[n-1][i]);
                    }
                } else {
                    for(int i = 0; i < n; i++) {
                        for(int j = 0; j < m-1; j++) {
                            System.out.print(grid[i][j] + " ");
                        }
                        System.out.println(grid[i][m-1]);
                    }
                }
            }else{
                System.out.println("NO");

            }
        }
    }
}
